
/*
 * Copyright (C) 2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: XMLStringField.java 188 2009-11-12 18:34:46Z archie.cobbs $
 */

package org.dellroad.sidekar.xml;

import org.dellroad.sidekar.StringField;

/**
 * Container for a {@link StringField}'s value during the Sidekar XML import/export process.
 */
class XMLStringField extends XMLAtomicField<String> {

    private String value;
    private boolean isNull;

    // Used during unmarshalling
    private XMLStringField(XMLItem xmlItem) {
        super(xmlItem);
    }

    // Used during unmarshalling
    private XMLStringField(XMLField xmlField) {
        super(xmlField);
    }

    // Used during marshalling
    public XMLStringField(String name, String value) {
        super(name);
        this.value = value;
        this.isNull = value == null;
    }

    // Used during unmarshalling
    @Override
    public String getObjectValue() {
        return this.isNull ? null : this.value;
    }

    // Used during unmarshalling
    public static XMLStringField newInstance(Object obj) {
        return obj instanceof XMLItem ? new XMLStringField((XMLItem)obj) : new XMLStringField((XMLField)obj);
    }
}

